package com.redis.jedis;

import org.junit.Test;
import redis.clients.jedis.*;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: lizehui
 * @Description:
 * @Date: 2022/11/02/09:52
 */
public class JedisTest {

    /**
     * @Author: lizehui
     * @Description: Jedis单机版
     * @Date: 2022/11/2 10:21
     */
    @Test
    public void testStandalone(){
        Jedis jedis = new Jedis("172.16.190.139",6379);
        jedis.set("name","testStandalone");
        String value = jedis.get("name");
        System.out.println(value);
    }

    /**
     * @Author: lizehui
     * @Description: Jedis连接池
     * @Date: 2022/11/2 10:41
     */
    @Test
    public void testPool(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        //设置最大连接数
        jedisPoolConfig.setMaxTotal(20);
        //设置最大
        jedisPoolConfig.setMaxIdle(5);
        jedisPoolConfig.setMinIdle(3);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig,"172.16.190.139",6379);
        Jedis jedis = jedisPool.getResource();
        jedis.set("name","testPool");
        String value = jedis.get("name");
        System.out.println(value);
    }

    /**
     * @Author: lizehui
     * @Description: Jedis集群
     * @Date: 2022/11/2 11:11
     */
    @Test
    public void testCluster(){
        Set<HostAndPort> set = new HashSet<>();
        set.add(new HostAndPort("172.16.190.139",7001));
        set.add(new HostAndPort("172.16.190.139",7002));
        set.add(new HostAndPort("172.16.190.139",7003));
        set.add(new HostAndPort("172.16.190.139",7004));
        set.add(new HostAndPort("172.16.190.139",7005));
        set.add(new HostAndPort("172.16.190.139",7006));
        JedisCluster jedisCluster = new JedisCluster(set);
        jedisCluster.set("name","testCluster");
        String value = jedisCluster.get("name");
        System.out.println(value);
    }


}
